package com.dingding.service.core.common.service.impl;

import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.dingding.common.core.beans.special.Specialuservehicleinfo;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.facade.user.common.dto.common.ReqGetDriverAuthStatus;
import com.dingding.facade.user.common.dto.common.ReqRegisterDriverDTO;
import com.dingding.facade.user.common.dto.common.ResGetDriverAuthStatus;
import com.dingding.service.core.common.dao.IDriverDao;
import com.dingding.service.core.common.service.IDriverService;

/**
 * 
 * @ClassName: DriverServiceImpl 
 * @Description: 司机业务逻辑实现类
 * @author YHQ
 * @date 2016年12月3日 下午6:02:30
 * @since V2.5.7
 * 
 */
@Component("driverService")
public class DriverServiceImpl implements IDriverService{

	@Resource(name = "driverDao")
	private IDriverDao driverDao;
	
	/**
	 * 
	 * @Title: registerDriver 
	 * @Description: 注册司机(出租车、专车使用) 
	 * @param registerDriverDTO 注册司机请求Bean
	 * @author YHQ 
	 * @since V2.5.7 
	 * @return String 用户Id
	 * 
	 */
	@Override
	public String registerDriver(ReqRegisterDriverDTO registerDriverDTO) {
		
		// 验证客户端请求参数是否空
		if(registerDriverDTO == null || !ToolUtil.validateParam(registerDriverDTO)){
			return null;
		}
		
		// 创建用户Id
		String uuid = UUID.randomUUID().toString();
		
		// 初始化用户
		boolean flag = driverDao.registerDriver(uuid,registerDriverDTO);
		
		if(flag){
			return uuid;
		}
				
		return null;
	}

	/**
	 * 
	 * @Title: getDriverAuthStatus 
	 * @Description: 获取司机认证状态
	 * @param reqGetDriverAuthStatus 客户端请求参数
	 * @author YHQ 
	 * @since V2.5.7
	 * @return ResGetDriverAuthStatus    返回类型
	 * 
	 */
	@Override
	public ResGetDriverAuthStatus getDriverAuthStatus(ReqGetDriverAuthStatus reqGetDriverAuthStatus) {
		
		// 验证客户端请求参数是否为空
		if(reqGetDriverAuthStatus == null || !ToolUtil.validateParam(reqGetDriverAuthStatus)){
			return null;
		}
		
		// 创建获取司机认证状态响应Bean
		ResGetDriverAuthStatus resGetDriverAuthStatus = new ResGetDriverAuthStatus();
		
		// 根据用户Id获取用户信息
		Specialuservehicleinfo specialuservehicleinfo = driverDao.getSpecialUserVehicleInfo(reqGetDriverAuthStatus.getUserId());
		
		// 用户信息不为空，则给响应Bean赋值(审核状态)
		if(specialuservehicleinfo != null){
			resGetDriverAuthStatus.setSuvStatus(specialuservehicleinfo.getSuvStatus());
		}
		
		return resGetDriverAuthStatus;
	}

}
